<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>

        <el-card>
            <el-row>
                <el-col :span="8">
                    <el-input placeholder="请输入内容" v-model="queryInfo.query">
                        <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <el-table :data="orderlist" border style="width: 100%">
                <el-table-column type="index">
                </el-table-column>
                <el-table-column prop="order_number" label="订单编号" width="400">
                </el-table-column>
                <el-table-column prop="order_price" label="订单价格" width="80">
                </el-table-column>
                <el-table-column prop="pay_status" label="是否付款" width="100">
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.pay_status === '1' ? 'success':'danger'">
                            {{scope.row.pay_status === '1' ? '已发货':'未发货'}}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="is_send" label="是否发货" width="100">
                </el-table-column>
                <el-table-column prop="create_time" label="下单时间" width="180">
                    <template slot-scope="scope">
                        {{scope.row.create_time | dataFormat}}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="200">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" class="el-icon-edit" @click="editClick">修改</el-button>
                        <el-button type="success" size="mini" class="el-icon-loading" @click="progressClick(scope.row)">
                            查看物流
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--            分页区域-->
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="queryInfo.pagenum"
                    :page-sizes="[1, 2, 3, 10]"
                    :page-size="queryInfo.pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total" background>
            </el-pagination>
        </el-card>
        <!--        修改地址的弹框-->
        <el-dialog
                title="修改地址"
                :visible.sync="editDialogVisible"
                width="50%" @close="editClose">
            <el-form :model="addressForm" :rules="addressFormRules" ref="addressForm" label-width="100px"
                     class="demo-ruleForm">
                <el-form-item label="省市县/区" prop="city">
                    <el-cascader
                            expandTrigger='hover'
                            v-model="addressForm.city"
                            :options="cityData"
                            :props="cityProps"
                            @change="handleChange"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address">
                    <el-input v-model="addressForm.address"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
    <el-button @click="editDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="editDialogVisible = false">确 定</el-button>
  </span>
        </el-dialog>
        <!--        查看物流的弹框-->
        <el-dialog
                title="查看物流信息"
                :visible.sync="progressDialogVisible"
                width="50%" @close="progressClose">
            <!--            时间线区域-->
            <el-timeline :reverse="reverse">
                <el-timeline-item
                        v-for="(activity, index) in progressInfo"
                        :key="index"
                        :timestamp="activity.ftime">
                    {{activity.context}}
                </el-timeline-item>
            </el-timeline>
            <span slot="footer" class="dialog-footer">
    <el-button @click="progressDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="progressDialogVisible = false">确 定</el-button>
  </span>
        </el-dialog>
    </div>
</template>

<script>
  import cityData from './citydata'

  export default {
    name: "Order",
    data() {
      return {
        queryInfo: {
          query: '',
          pagenum: 1,
          pagesize: 10,
        },
        total: 0,
        orderlist: [],
        editDialogVisible: false,
        addressForm: {
          city: [],
          address: '',
        },
        addressFormRules: {
          city: [{required: true, message: '请选择具体城市', trigger: 'blur'}],
          address: [{required: true, message: '请输入详细地址', trigger: 'blur'}],
        },
        cityData,
        //级联选择器的配置
        cityProps: {
          label: cityData.label,
          value: cityData.value,
          children: cityData.children
        },
        progressDialogVisible: false,
        progressInfo: [],
        reverse: true,
      }
    },
    methods: {
      //获取所有的订单数据
      async getOrderList() {
        const {data: res} = await this.$http.get(`orders`, {params: this.queryInfo})
        if (res.meta.status !== 200) return this.$message.error('获取订单数据失败')
        //保存数据
        this.orderlist = res.data.goods
        this.total = res.data.total
      },

      //页码改变时触发
      handleSizeChange(newSize) {
        this.queryInfo.pagesize = newSize
        this.getOrderList()
      },
      //页数改变时触发
      handleCurrentChange(newPage) {
        this.queryInfo.pagenum = newPage
        this.getOrderList()
      },
      // 修改按钮的点击
      editClick() {
        this.editDialogVisible = true
      },
      //查看物流按钮的点击
      async progressClick(row) {
        //发起获取物流信息的数据请求
        const {data: res} = await this.$http.get(`/kuaidi/1106975712662`)
        if (res.meta.status !== 200) this.$message.error('获取物流信息失败')
        this.$nextTick( ()=>{
          this.progressInfo = res.data
        })
        this.progressDialogVisible = true
        console.log(this.progressInfo);
      },
      //级联选择器的值改变
      handleChange() {
      },
      //关闭修改弹框
      editClose() {
        this.$refs.addressForm.resetFields()
        this.editDialogVisible = false
      },
      //关闭物流弹框
      progressClose() {

      }
    },
    created() {
      this.getOrderList()
    },
    computed: {}
  }
</script>

<style scoped>

</style>